package com.ymatou.iapi.im.testcase;

import com.ymatou.iapi.im.parameter.SendMessageToBuyerBean;
import com.ymatou.iapi.im.parameter.SendMessageToSellerBean;
import com.ymatou.iapi.im.parameter.SetSessionSilentBean;
import com.ymatou.iapi.im.service.SetSessionSilentCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymttest.business.service.ImCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

import java.util.Map;

/**
*取消会话免打扰
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetSessionSilent{
	private static SetSessionSilentBean setsessionsilentBean;
	private static SetSessionSilentCall setsessionsilentCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("取消会话免打扰");
	}

	@Before
	public void caseUp() {
		setsessionsilentBean=new SetSessionSilentBean();
		setsessionsilentCall=new SetSessionSilentCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setsessionsilentCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSessionSilent_01() {
		Logger.start(true,"设置会话免打扰");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();
			int fromUserId = 24635724;
			SendMessageToBuyerBean sendMessageToBuyerBean = ImCallService.initSendMessageToBuyerBean(fromUserId,userId,"你好");
			ImCallService.SendMessageToBuyer(sendMessageToBuyerBean);

			setsessionsilentBean.setFromUserId(fromUserId);
			setsessionsilentBean.setToUserId(userId);
			setsessionsilentCall.setData(setsessionsilentBean);
			setsessionsilentCall.callService();
			Logger.verifyEquals("Success",setsessionsilentCall.getString("Status"),"验证Status");
			Map map = new ImDefaultWapper().selectTotalCount(userId,fromUserId).get(0);
			Logger.verifyEquals(1,Integer.parseInt(map.get("Slient").toString()),"验证是否设置免打扰");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSessionSilent_02() {
		Logger.start(true,"和101设置会话免打扰");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();
			int fromUserId = 20336378;
			SendMessageToBuyerBean sendMessageToBuyerBean = ImCallService.initSendMessageToBuyerBean(fromUserId,userId,"你好");
			ImCallService.SendMessageToBuyer(sendMessageToBuyerBean);

			setsessionsilentBean.setFromUserId(fromUserId);
			setsessionsilentBean.setToUserId(userId);
			setsessionsilentCall.setData(setsessionsilentBean);
			setsessionsilentCall.callService();
			Logger.verifyEquals("Success",setsessionsilentCall.getString("Status"),"验证Status");
			Map map = new ImDefaultWapper().selectTotalCount(userId,fromUserId).get(0);
			Logger.verifyEquals(1,Integer.parseInt(map.get("Slient").toString()),"验证是否设置免打扰");
			Logger.verifyEquals(0,Integer.parseInt(map.get("UnReadCount").toString()),"未读数为0");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}